package com.asyf.consumer.config;

import feign.Request;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;

import java.util.concurrent.TimeUnit;

@Slf4j
//@Configuration
public class FeignSingleThreadPoolConfig {

    /**
     * 配置优先级
     * default-to-properties: true时 -> 此配置低于feign.client.config.default.read-timeout=10000
     * default-to-properties: false时 -> 此配置高于feign.client.config.default.read-timeout=10000
     * @return
     */
    @Bean
    @Primary
    public Request.Options options() {
        return new Request.Options(3, TimeUnit.SECONDS, 3, TimeUnit.SECONDS, true);
    }

    @Bean
    public RequestInterceptor customFeignInterceptor() {
        RequestInterceptor requestInterceptor = new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate requestTemplate) {
                log.info("apply----" + Thread.currentThread());
                log.info("hashCode----" + requestTemplate.hashCode());
            }
        };
        return requestInterceptor;
    }

}
